<template>
  <div style=" width: 100%; margin: auto;">
    <h3>现金流量表</h3>
    <h4>（截止到本年度12月31日）
      单位：元</h4>
    <el-row style="border-left: 1px solid #ebeef5;border-top: 1px solid #ebeef5;background:#F0F5FA;color:#333333;font-weight: bold;">
      <el-col class="e-col" :span="2">行次</el-col>
      <el-col class="e-col" :span="12">项目</el-col>
      <el-col class="e-col" :span="10">金额</el-col>
    </el-row>
    <el-row style="border-left: 1px solid #ebeef5;" v-for="(item,index) in listForm" :key="index">
      <el-col class="e-col" :span="2">{{ item.fieldSort }}</el-col>
      <el-col class="e-col" :span="12">{{ item.assetTermName }}</el-col>
      <el-col class="e-col" :span="10">
        <el-input @input="setValue()" style="width: 80%;height: 30px;margin-top: -3px;" :precision="2"
                  :disabled="item.fieldSort == 7 || item.fieldSort == 12 || item.fieldSort == 13 || item.fieldSort == 19 || item.fieldSort == 23 || item.fieldSort == 24 || item.fieldSort == 28 || item.fieldSort == 32 || item.fieldSort == 33"
                  v-show="item.fieldSort != 1 && item.fieldSort != 14 && item.fieldSort != 25"  size="default"
                  v-model="item.amount" />
      </el-col>
    </el-row>
  </div>
</template>
<script>

import { getTableInfoByPage, mfSaveCash } from '@/views/yearCheck/ykb/mf/mf'

export default {
  data() {
    return {
      listForm: []
    }
  },

  created() {

  },
  methods: {
    postInfo() {
      for (let i = 0; i < this.listForm.length; i++) {
        this.listForm[i].creditCode = localStorage.getItem('creditCode')
        this.listForm[i].examineYear = localStorage.getItem('examineYear')
        this.listForm[i].organizationBaseId = '1'
        if(this.listForm[i].amount != null && this.listForm[i].amount != ''){
          this.listForm[i].amount = parseFloat(this.listForm[i].amount).toFixed(2);
        }
      }
      console.log(this.listForm)
      for (let i = 0; i < this.listForm.length; i++) {
        let noYz = '-1-7-12-13-14-19-23-25-28-32-'
        let amountValue = this.listForm[i].amount + "";
        if (noYz.indexOf('-' + this.listForm[i].fieldSort + '-') == -1) {
          if (amountValue == null || amountValue == '') {
            this.$message({
              message: '请填写第' + this.listForm[i].fieldSort + '行数据！',
              type: 'warning'
            })
            return
          }
        }
      }
      mfSaveCash(this.listForm).then(response => {
        this.$message({
          message: '保存现金流量表成功！',
          type: 'success'
        })
        this.getInfo();
      })
    },
    setValue() {
      let numbers = [this.getStr(this.listForm[0].amount), this.getStr(this.listForm[1].amount), this.getStr(this.listForm[2].amount), this.getStr(this.listForm[3].amount), this.getStr(this.listForm[4].amount), this.getStr(this.listForm[5].amount)]
      this.listForm[6].amount = 0;
      for (let i = 0; i < numbers.length; i++) {
        this.listForm[6].amount += numbers[i];
      }
      let numbers2 = [this.getStr(this.listForm[7].amount),this.getStr(this.listForm[8].amount),this.getStr(this.listForm[9].amount),this.getStr(this.listForm[10].amount)];
      this.listForm[11].amount = 0;
      for (let i = 0; i < numbers2.length; i++) {
        this.listForm[11].amount += numbers2[i];
      }

      let numbers3 = [this.getStr(this.listForm[14].amount),this.getStr(this.listForm[15].amount),this.getStr(this.listForm[16].amount),this.getStr(this.listForm[17].amount)];
      this.listForm[18].amount = 0;
      for (let i = 0; i < numbers3.length; i++) {
        this.listForm[18].amount += numbers3[i];
      }

      let numbers4 = [this.getStr(this.listForm[19].amount),this.getStr(this.listForm[20].amount),this.getStr(this.listForm[21].amount)];
      this.listForm[22].amount = 0;
      for (let i = 0; i < numbers4.length; i++) {
        this.listForm[22].amount += numbers4[i];
      }

      let numbers5 = [this.getStr(this.listForm[25].amount),this.getStr(this.listForm[26].amount)];
      this.listForm[27].amount = 0;
      for (let i = 0; i < numbers5.length; i++) {
        this.listForm[27].amount += numbers5[i];
      }

      let numbers6 = [this.getStr(this.listForm[28].amount),this.getStr(this.listForm[29].amount),this.getStr(this.listForm[30].amount)];
      this.listForm[31].amount = 0;
      for (let i = 0; i < numbers6.length; i++) {
        this.listForm[31].amount += numbers6[i];
      }

      this.listForm[12].amount = (Number(this.listForm[6].amount) - Number(this.listForm[11].amount)).toFixed(2)
      this.listForm[23].amount = Number(this.listForm[18].amount) - Number(this.listForm[22].amount)
      console.log(this.listForm[23].amount)
      this.listForm[32].amount = Number(this.listForm[27].amount) - Number(this.listForm[31].amount)
      this.listForm[34].amount = Number(this.listForm[12].amount) + Number(this.listForm[23].amount)
        + Number(this.listForm[32].amount) + Number(this.listForm[33].amount)
      // this.listForm[13].amount = Number(this.listForm[6].amount) - Number(this.listForm[11].amount)
    },
    getStr(str) {
      if (str == null || str == '') {
        str = 0
      } else {
        str = parseFloat(str)
      }
      return str
    },

    getInfo() {
      getTableInfoByPage(20).then(response => {
        console.log(response.data)
        this.listForm = JSON.parse(JSON.stringify(response.data).replace(/null/g, '""'));
      })
    }
  }
}
</script>
<style scoped lang="scss">
.el-table {
  --el-table-row-hover-bg-color: rgba(39, 137, 238, 0.1);
  --el-table-border-color:#e0e5f0;
}
:deep(.el-card.is-always-shadow) {
  box-shadow: 0 1px 14px 0 rgba(209, 224, 239, 0.6)
}

/* 拉框选中 */
.el-select-dropdown__item {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

/* 鼠标经过下拉框 */
.el-select-dropdown__item:hover {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

.el-select-dropdown__item.selected {
  color: #2789EE;
}
.app-container {
  margin-top: 40px;
  margin-left: 15%;
  width: 70%;
}

.div-bg {
  width: 100%;
  background: #F0F0F0;
  height: 10px;
}

.box-card {
  width: 100%;
  margin-top: 20px;
  padding: 20px;
}

.el-col {
  padding-left: 5px;
}

.divider-title {
  font-weight: bold;
  font-size: 18px;
}

.custom-select .el-select-dropdown {
  max-height: 600px; /* 设置为你想要的高度 */
  overflow: auto; /* 添加滚动条 */
}

table {
  border-collapse: collapse; /* 确保表格的边框合并为单一边框 */
  width: 100%; /* 表格宽度 */
}

td {
  border: 1px solid #ababab; /* 设置单线边框 */
  padding: 6px; /* 单元格内边距 */
}

.e-col {
  border-right: 1px solid #ebeef5;
  border-bottom: 1px solid #ebeef5;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
}
.el-form-item {
  margin-bottom: 0px;
}
</style>
